/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jeelabs.lab2;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author mariusz.gomse
 */
@Entity
@Table(name = "CAVE")
@NamedQueries({
    @NamedQuery(name = "Cave.findAll", query = "SELECT c FROM Cave c"),
    @NamedQuery(name = "Cave.findById", query = "SELECT c FROM Cave c WHERE c.id = :id"),
    @NamedQuery(name = "Cave.findByDimension", query = "SELECT c FROM Cave c WHERE c.dimension = :dimension")})
public class Cave implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "ID")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 128)
    @Column(name = "DIMENSION")
    private String dimension;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "cave")
    private Collection<Dragon> dragonCollection;

    public Cave() {
    }

    public Cave(Integer id) {
        this.id = id;
    }

    public Cave(Integer id, String dimension) {
        this.id = id;
        this.dimension = dimension;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getDimension() {
        return dimension;
    }

    public void setDimension(String dimension) {
        this.dimension = dimension;
    }

    public Collection<Dragon> getDragonCollection() {
        return dragonCollection;
    }

    public void setDragonCollection(Collection<Dragon> dragonCollection) {
        this.dragonCollection = dragonCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Cave)) {
            return false;
        }
        Cave other = (Cave) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "jeelabs.lab2.Cave[ id=" + id + " ]";
    }
    
}
